﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Markup;

namespace UIT.Controls.Containers
{
#if !SILVERLIGHT
    [RuntimeNameProperty("Id")]
#endif
    [ContentProperty("Children")]
    public class Panel : DrawableControl, IContainer
    {

        public T FindControl<T>(string id) where T : IControl
        {
            return (T)UIT.Context.Current.Application.ControlFinder.Find(id, this);
        }


        public Panel()
        {
            children = new ControlCollection<IControl>(this);
        }

        private IDisposableObservableCollection<IContainer, IControl> children;

        public IDisposableObservableCollection<IContainer, IControl> Children
        {
            get { return children; }
        }

        public override ControlType Type
        {
            get { return ControlType.Container; }
        }

        public override bool IsContainer
        {
            get
            {
                return true;
            }
        }

        #region IDisposable Members

        public override void Dispose()
        {
            base.Dispose();
            if (children != null)
            {
                children.Dispose();
                children = null;
            }
        }

        #endregion
    }
}
